package com.t.blog.controller;

import com.t.blog.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.t.pro.pojo.AdminQueryArticlePojo;
import org.t.pro.pojo.AdminSaveArticlePojo;
import t.microservices.fw.common.interResult.R;

import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 * 〈文章管理控制器〉
 *
 * @author a0000
 * @create 2024/2/5 23:02
 * @since 1.0.0
 */
@RestController
@CrossOrigin
@RequestMapping("article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;



    @GetMapping
    public R<List<AdminQueryArticlePojo>> getArticleList(){
        return R.success(articleService.getArticleList());
    }



    @GetMapping("/{id}")
    public R<AdminQueryArticlePojo> getArticleContent(AdminQueryArticlePojo pojo){
        AdminQueryArticlePojo articleContentById = articleService.getArticleContentById(pojo);
        return R.success(articleContentById);
    }

    @PostMapping
    public R saveArticleInfo(@RequestBody AdminSaveArticlePojo pojo){
        articleService.saveArticle(pojo);
        return R.success();
    }

    @PutMapping
    public R motifyArticleInfo(@RequestBody AdminSaveArticlePojo pojo){
        articleService.motifyArticle(pojo);
        return R.success();
    }
}
